package com.mmlc.meimei.lichengkongjian.Adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mmlc.meimei.lichengkongjian.App;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.responsebean.PhysicalStoreListResponseBean;

import java.util.List;

public class PhysicalStoreAdapter extends BaseAdapter {

    List<PhysicalStoreListResponseBean.DataBean.StoreBean> item;
    Context context;


    public PhysicalStoreAdapter(Context context, List<PhysicalStoreListResponseBean.DataBean.StoreBean> item) {
        this.context = context;
        this.item = item;
    }

    @Override
    public int getCount() {
        return item.size();
    }

    @Override
    public PhysicalStoreListResponseBean.DataBean.StoreBean getItem(int i) {
        return item.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        final PhysicalStoreListResponseBean.DataBean.StoreBean bean = item.get(i);
        if (view == null) {
            view = App.layoutInflater.inflate(R.layout.item_physical_store, viewGroup, false);
        }
        TextView tv_title = (TextView) view.findViewById(R.id.tv_name);
        tv_title.setText(bean.getName());

        TextView tv_sub = (TextView) view.findViewById(R.id.tv_sub);
        tv_sub.setText(bean.getDetail_address());

        ImageView iv_call=(ImageView) view.findViewById(R.id.iv_phone);
        iv_call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callPhone(bean.getStore_phone().replaceAll("-",""));
            }
        });

        return view;

    }

    private void callPhone(String phoneno) {
        Intent intent=new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+phoneno));
        context.startActivity(intent);
    }

}

